package com.atguigu.gmall.item.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 自定义线程池配置类
 */
@Configuration
public class ItemThreadPollConfig {
    @Bean
    public ThreadPoolExecutor threadPoolExecutor(){
        ThreadPoolExecutor threadPoolExecutor =
                new ThreadPoolExecutor(
                        12,//核心线程数
                        24,//最大线程数
                        5,//最大存活时间
                        TimeUnit.SECONDS,//时间单位
                        new ArrayBlockingQueue<>(10000),//等待队列
                        Executors.defaultThreadFactory(),//线程工厂 默认
                        new ThreadPoolExecutor.AbortPolicy()//拒绝策略
                );
        return threadPoolExecutor;
    }
}
